package com.frxuexi.video

import com.frxuexi.lib_base.entity.CommentBean
import com.frxuexi.lib_base.entity.CommentBeanItem
import com.frxuexi.lib_base.entity.FocuseBean
import com.frxuexi.lib_base.entity.VideoBean
import com.frxuexi.lib_base.http.VideoApiService
import com.frxuexi.lib_base.mvvm.BaseViewModel
import com.frxuexi.lib_base.room.FocuseDao
import com.frxuexi.lib_base.room.FocuseEntity
import com.frxuexi.lib_base.room.LoveDao
import com.frxuexi.lib_base.room.LoveEntity
import com.frxuexi.lib_base.utils.SignLiveData
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class VideoViewModel @Inject constructor(val apiService: VideoApiService,val loveDao: LoveDao,val focuseDao: FocuseDao):BaseViewModel() {

    val videoData=SignLiveData<VideoBean>()
    val videoError=SignLiveData<String>()
    fun getVideos(page:Int,pagesize:Int){
        httpRequest({apiService.getVideos(page, pagesize)},videoData::postValue,videoError::postValue)
    }

    val addZanData=SignLiveData<Long>()
    fun addLove(loveEntity: LoveEntity){
        roomRequest({loveDao.addLove(loveEntity)},addZanData::postValue,videoError::postValue)
    }

    val isZanData=SignLiveData<LoveEntity>()
    fun isLove(id:Int){
        roomRequest({loveDao.isLove(id)},isZanData::postValue,videoError::postValue)
    }

    val deleteZanData=SignLiveData<Int>()
    fun deleteZan(loveEntity: LoveEntity){
        roomRequest({loveDao.deleteLove(loveEntity)},deleteZanData::postValue,videoError::postValue)
    }

    val commentData=SignLiveData<CommentBean>()
    fun getComments(vid:String){
        httpRequest({apiService.getComments(vid)},commentData::postValue,videoError::postValue)
    }

    val addCommentData=SignLiveData<CommentBeanItem>()
    fun addComment(item:CommentBeanItem){
        httpRequest({apiService.addComment(toBody(item))},addCommentData::postValue,videoError::postValue)
    }

    /*val focuseData=SignLiveData<FocuseBean>()
    fun getFocuse(id:Int){
        httpRequest({apiService.getFocuse(id)},focuseData::postValue,videoError::postValue)
    }*/

    val addFocuseData=SignLiveData<Long>()
    fun addFocuse(focuseEntity: FocuseEntity){
        roomRequest({focuseDao.addFocuse(focuseEntity)},addFocuseData::postValue,videoError::postValue)
    }

    val isFocuseData=SignLiveData<FocuseEntity>()
    fun isFocuse(id:Long){
        roomRequest({focuseDao.isFocuse(id)},isFocuseData::postValue,videoError::postValue)
    }

    val deleteFocuseData=SignLiveData<Int>()
    fun deleteFocuse(focuseEntity: FocuseEntity){
        roomRequest({focuseDao.deleteFocuse(focuseEntity)},deleteFocuseData::postValue,videoError::postValue)
    }


}